# -*- coding: utf-8 -*-
from web import models
from django import forms

from web.forms.bootstrap import BootStrapForm


class WikiForm(BootStrapForm, forms.ModelForm):
    
    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        # 重定义添加文章时，选择父类的文章：即筛选出本项目的首页文章，而不是所有的文章
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
        choices = [('', '请选择'), ]
        choices.extend(data_list)
        self.fields['parent'].choices = choices  # 覆盖数据
    
    class Meta:
        model = models.Wiki
        # 在Form中不显示的字段
        exclude = ['project', 'depth', ]
